package com.yiqi.liebang.feature.home.view;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.liebang.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class QuestionListActivity extends BaseActivity {


    @BindView(R.id.tl_4)
    SlidingTabLayout mTabLayout;

    @BindView(R.id.vp)
    ViewPager mVp;
    @BindView(R.id.btn_ask)
    TextView mBtnAsk;

    private ArrayList<Fragment> mFragments = new ArrayList<>();

    private final String[] mTitles = {
            "话题", "问答"
    };
    private boolean isTopic = true;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_question_list;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        isTopic = this.getIntent().getBooleanExtra("is_topic", true);
        initFilterDropDownView();

    }

    private void initFilterDropDownView() {
        mFragments.add(new Topic2Fragment());
        mFragments.add(new AskFragment());
        mTabLayout.setViewPager(mVp, mTitles, this, mFragments);
        mTabLayout.setCurrentTab(isTopic ? 0 : 1);
        mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {

                mBtnAsk.setVisibility(position==1?View.VISIBLE:View.GONE);
            }

            @Override
            public void onTabReselect(int position) {

                mBtnAsk.setVisibility(position==1?View.VISIBLE:View.GONE);
//                mBtnAsk.setVisibility(position==0?View.GONE:View.VISIBLE);
            }


        });

        mVp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mBtnAsk.setVisibility(position==1?View.VISIBLE:View.GONE);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


    }

    @Override
    protected void initData() {

    }


    @OnClick({R.id.btn_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;

        }
    }


    @OnClick(R.id.btn_ask)
    public void onViewClicked() {
        startActivity(new Intent(this,AskActivity.class));
    }
}
